//
//  GYGoodsRecommed.m
//  GoodLuck
//
//  Created by 郭为勇 on 2018/3/9.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "GYGoodsRecommed.h"

@implementation GYGoodsRecommed

+ (NSArray *)loadRecommendData:(NSArray *)source {
    NSMutableArray *models = [NSMutableArray array];
    for (NSDictionary *dic in source) {
        GYGoodsRecommed *goods = [[GYGoodsRecommed alloc] initWithDic:dic];
        [models addObject:goods];
    }
    
    return models;
}

- (instancetype)initWithDic:(NSDictionary *)dic {
    self = [super init];
    if (self) {
        
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}

- (NSString *)description {
    NSArray *keys = @[@"goods_id",@"goods_name",@"goods_price",@"goods_promotion_price",@"goods_image_url"];
    
    return [NSString stringWithFormat:@"%@",[self dictionaryWithValuesForKeys:keys]];
}


- (CGFloat)returnModelHeight {
    CGFloat height = (ScreenWidth-30)/2;
    
    //计算文字高度
    CGFloat nameHeight = [self.goods_name boundingRectWithSize:CGSizeMake((ScreenWidth-30)/4, 999) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil].size.height;
    
    CGFloat priceHeight = [[NSString stringWithFormat:@"%@",self.goods_price] boundingRectWithSize:CGSizeMake((ScreenWidth-50)/4, 999) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil].size.height;
    
    height += nameHeight +priceHeight + 10;
    
    return height;
}
@end
